<template>
  <div class="suggestion-container">
    <el-card class="suggestion-card">
      <div class="title">
        <span class="desc">建议反馈</span>
        <img class="icon" src="@/assets/img/item-img/suggestion.png" alt="" />
      </div>
      <div class="body">
        <p class="select-title">建议类别</p>
        <el-select v-model="value" placeholder="请选择建议类别">
          <el-option v-for="item in suggestionList" :key="item.id" :value="item.value"> </el-option>
        </el-select>
        <p class="select-desc">建议内容</p>
        <el-input type="textarea" :rows="15" placeholder="请输入建议内容" v-model="suggestionDesc"> </el-input>
        <div class="btn-container">
          <el-button type="primary" @click="commit">提交</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonServe from '../../api/service/common.serve'
export default {
  data() {
    return {
      id: window.sessionStorage.getItem('studentId'),
      value: '', //选择的建议类别
      suggestionDesc: '', //输入的建议内容
      suggestionList: [
        {
          id: 1,
          value: '平台'
        },
        {
          id: 2,
          value: '教室'
        },
        {
          id: 3,
          value: '道路'
        },
        {
          id: 4,
          value: '图书馆'
        },
        {
          id: 5,
          value: '宿舍'
        },
        {
          id: 6,
          value: '其他'
        }
      ]
    }
  },
  methods: {
    getImg(src) {
      return require('@/assets/img/item-img/' + src)
    },
    // 提交建议
    commit() {
      let params = {
        adviceContent: this.suggestionDesc,
        adviceType: this.value
      }
      if (!this.value || !this.suggestionDesc) return this.$message.info('建议类型或建议内容不能为空')
      commonServe
        .commitSuggestion(this.id, params)
        .then((res) => {
          console.log(res)
          if (res.code === 200) {
            this.$message.success('提交反馈建议成功')
            this.value = ''
            this.suggestionDesc = ''
          } else {
            this.$message.warning('提交建议失败')
          }
        })
        .catch((err) => {
          this.$message(err.message)
        })
    }
  }
}
</script>

<style lang="less" scoped>
.suggestion-container {
  .suggestion-card {
    .title {
      display: flex;
      align-items: center;
      .desc {
        font-size: 30px;
        color: #3a62d7;
        letter-spacing: 10px;
        font-weight: bold;
        text-shadow: 2px 2px 5px #999;
      }
      .icon {
        width: 40px;
        height: 40px;
      }
      .icon:hover {
        transform: translateY(-5px);
        transition: 0.5s;
      }
    }
    .body {
      padding: 50px 200px 0 200px;
      .select-title {
        color: #999;
      }
      .el-select {
        width: 100%;
      }
      .select-desc {
        color: #999;
        padding-top: 20px;
      }
      .btn-container {
        padding: 100px 0 10px 0;
        .el-button {
          width: 100%;
          color: #fff;
        }
      }
    }
  }
}
</style>
